package edu.dut.yz.webdemo.controller;

import edu.dut.yz.webdemo.bean.Result;
import edu.dut.yz.webdemo.bean.User;
import edu.dut.yz.webdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userservice;

    @PostMapping("/login")
    public Result login(User user){
        return userservice.login(user);
    }

    @PostMapping("/regist")
    @ResponseBody
    public Result regist(@RequestBody Map<String,Object> map){
        User user=new User();
        user.setUsername((String)map.get("username"));
        user.setPassword((String)map.get("password"));
        user.setUsertype(Integer.parseInt((String)map.get("usertype")));
        return userservice.regist(user);
    }

}
